#ifndef __DIM_SUM_SCHED_H
#define __DIM_SUM_SCHED_H

#ifdef __KERNEL__
#include <kapi/dim-sum/task.h>
#include <uapi/dim-sum/sched.h>
#include <dim-sum/linkage.h>
#include <dim-sum/process.h>
#include <dim-sum/ref.h>
#include <dim-sum/time.h>
#include <dim-sum/wait.h>
#include <dim-sum/bitops.h>

#include <asm/current.h>
#include <asm/processor.h>

struct tty_struct;
struct wait_queue;
struct task_fs_context;
struct task_file_handles;
struct blkdev_infrast;

/**
 * 任务标志
 */
enum {
	/**
	 * 系统IDLE任务
	 */
	__TASKFLAG_IDLE= 0,
	/**
	 * OSEK基本任务
	 */
	__TASKFLAG_BASE,
	/**
	 * OSEK扩展任务
	 */
	__TASKFLAG_EXTENDED,
	/**
	 * 不要冻结此任务
	 */
	__TASKFLAG_NOFREEZE,
	/**
	 * 任务正在被冷冻
	 */
	__TASKFLAG_FREEZING,
	/**
	 * 任务已经被冷冻
	 */
	__TASKFLAG_FROZEN,
	/**
	 * 任务正在执行内存回收
	 * 也就是可以突破内存水线
	 */
	__TASKFLAG_RECLAIM,
	/**
	 * 正在执行同步写，例如在调用fsync
	 */
	__TASKFLAG_SYNCWRITE,
	/**
	 * 当前任务是后台回写任务
	 */
	__TASKFLAG_FLUSHER,
	/**
	 * 进程被信号杀死
	 */
	__TASKFLAG_SIGNALED,

	/* I'm a virtual CPU */
	__TASKFLAG_VCPU,

	/* Getting shut down */
	__TASKFLAG_EXITING,

	/* Task is an IO worker */
	__TASKFLAG_IO_WORKER,

	__TASKFLAG_WQ_WORKER,			/* I'm a workqueue worker */
	__TASKFLAG_FORKNOEXEC,			/* Forked but didn't exec */
	__TASKFLAG_MCE_PROCESS,      	/* Process policy on mce errors */
	__TASKFLAG_SUPERPRIV,			/* Used super-user privileges */
	__TASKFLAG_DUMPCORE,			/* Dumped core 0x11 */
	__TASKFLAG_MEMALLOC,			/* Allocating memory */
	__TASKFLAG_NPROC_EXCEEDED,		/* user_mgr_set_user() noticed that RLIMIT_NPROC was exceeded */
	__TASKFLAG_USED_MATH,			/* If unset the fpu must be initialized before use */
	__TASKFLAG_KSWAPD,				/* I am kswapd */
	__TASKFLAG_MEMALLOC_NOFS,		/* All allocation requests will inherit GFP_NOFS */
	__TASKFLAG_MEMALLOC_NOIO,		/* All allocation requests will inherit GFP_NOIO */
	__TASKFLAG_LOCAL_THROTTLE,		/* Throttle writes only against the bdi I write to, 0x18
						 				* I am cleaning dirty pages from some other bdi. */
	__TASKFLAG_KTHREAD,				/* I am a kernel thread */
	__TASKFLAG_RANDOMIZE,			/* Randomize virtual address space */
	__TASKFLAG_SWAPWRITE,			/* Allowed to write to swap */
	__TASKFLAG_NO_SETAFFINITY,		/* Userland is not allowed to meddle with cpus_mask */
	__TASKFLAG_MCE_EARLY,      		/* Early kill for mce process policy */
	__TASKFLAG_MEMALLOC_NOCMA,		/* All allocation request will have _GFP_MOVABLE cleared */
	__TASKFLAG_FREEZER_SKIP,		/* Freezer should not count it as freezable */
	__TASKFLAG_SUSPEND_TASK,     	/* This thread called freeze_processes() and should not be frozen  0x20*/
	__TASKFLAG_VFORK,	      		/* This thread called freeze_processes() and should not be frozen */

	TIF_SIGPENDING,
	TIF_NEED_RESCHED,
	TIF_NOTIFY_RESUME,
	TIF_FOREIGN_FPSTATE,
	TIF_NOHZ,
	TIF_SYSCALL_TRACE,
	TIF_SYSCALL_AUDIT,
	TIF_SYSCALL_TRACEPOINT,
	TIF_SECCOMP,
	TIF_UPROBE,
	TIF_FSCHECK,
	TIF_32BIT,
	TIF_SVE,
};

#define TF_IDLE 				(1 << __TASKFLAG_IDLE)
#define TF_BASE 				(1 << __TASKFLAG_BASE)
#define TF_EXTENDED 			(1 << __TASKFLAG_EXTENDED)
#define TASKFLAG_NOFREEZE		(1UL << __TASKFLAG_NOFREEZE)
#define TASKFLAG_FREEZING		(1UL << __TASKFLAG_FREEZING)
#define TASKFLAG_FROZEN			(1UL << __TASKFLAG_FROZEN)
#define TASKFLAG_RECLAIM		(1UL << __TASKFLAG_RECLAIM)
#define TASKFLAG_SYNCWRITE		(1UL << __TASKFLAG_SYNCWRITE)
#define TASKFLAG_FLUSHER		(1UL << __TASKFLAG_FLUSHER)
#define TASKFLAG_SIGNALED   	(1UL << __TASKFLAG_SIGNALED)

#define TF_OSEK (TF_BASE | TF_EXTENDED)

#define _TIF_SIGPENDING				(1ul << TIF_SIGPENDING)
#define _TIF_NEED_RESCHED			(1ul << TIF_NEED_RESCHED)
#define _TIF_NOTIFY_RESUME			(1ul << TIF_NOTIFY_RESUME)
#define _TIF_FOREIGN_FPSTATE		(1ul << TIF_FOREIGN_FPSTATE)
#define _TIF_NOHZ					(1ul << TIF_NOHZ)
#define _TIF_SYSCALL_TRACE			(1ul << TIF_SYSCALL_TRACE)
#define _TIF_SYSCALL_AUDIT			(1ul << TIF_SYSCALL_AUDIT)
#define _TIF_SYSCALL_TRACEPOINT		(1ul << TIF_SYSCALL_TRACEPOINT)
#define _TIF_SECCOMP				(1ul << TIF_SECCOMP)
#define _TIF_UPROBE					(1ul << TIF_UPROBE)
#define _TIF_FSCHECK				(1ul << TIF_FSCHECK)
#define _TIF_32BIT					(1ul << TIF_32BIT)
#define _TIF_SVE					(1ul << TIF_SVE)

#define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
				 _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
				 _TIF_UPROBE | _TIF_FSCHECK)

#define _TIF_SYSCALL_WORK	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
				 _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
				 _TIF_NOHZ)



/* These can be the second arg to send_sig_info/send_group_sig_info.  */
#define SEND_SIG_NOINFO ((struct siginfo *) 0)
#define SEND_SIG_PRIV	((struct siginfo *) 1)
#define SEND_SIG_FORCED	((struct siginfo *) 2)

#define PF_VCPU			0x00000001	/* I'm a virtual CPU */
#define PF_IDLE			0x00000002	/* I am an IDLE thread */
#define PF_EXITING		0x00000004	/* Getting shut down */
#define PF_IO_WORKER		0x00000010	/* Task is an IO worker */
#define PF_WQ_WORKER		0x00000020	/* I'm a workqueue worker */
#define PF_FORKNOEXEC		0x00000040	/* Forked but didn't exec */
#define PF_MCE_PROCESS		0x00000080      /* Process policy on mce errors */
#define PF_SUPERPRIV		0x00000100	/* Used super-user privileges */
#define PF_DUMPCORE		0x00000200	/* Dumped core */
#define PF_SIGNALED		0x00000400	/* Killed by a signal */
#define PF_MEMALLOC		0x00000800	/* Allocating memory */
#define PF_NPROC_EXCEEDED	0x00001000	/* user_mgr_set_user() noticed that RLIMIT_NPROC was exceeded */
#define PF_USED_MATH		0x00002000	/* If unset the fpu must be initialized before use */
#define PF_NOFREEZE		0x00008000	/* This thread should not be frozen */
#define PF_FROZEN		0x00010000	/* Frozen for system suspend */
#define PF_KSWAPD		0x00020000	/* I am kswapd */
#define PF_MEMALLOC_NOFS	0x00040000	/* All allocation requests will inherit GFP_NOFS */
#define PF_MEMALLOC_NOIO	0x00080000	/* All allocation requests will inherit GFP_NOIO */
#define PF_LOCAL_THROTTLE	0x00100000	/* Throttle writes only against the bdi I write to,
						 * I am cleaning dirty pages from some other bdi. */
#define PF_KTHREAD		0x00200000	/* I am a kernel thread */
#define PF_RANDOMIZE		0x00400000	/* Randomize virtual address space */
#define PF_SWAPWRITE		0x00800000	/* Allowed to write to swap */
#define PF_NO_SETAFFINITY	0x04000000	/* Userland is not allowed to meddle with cpus_mask */
#define PF_MCE_EARLY		0x08000000      /* Early kill for mce process policy */
#define PF_MEMALLOC_NOCMA	0x10000000	/* All allocation request will have _GFP_MOVABLE cleared */
#define PF_FREEZER_SKIP		0x40000000	/* Freezer should not count it as freezable */
#define PF_SUSPEND_TASK		0x80000000      /* This thread called freeze_processes() and should not be frozen */
#define PF_VFORK			0x20000000      /* This thread called freeze_processes() and should not be frozen */

#define PR_IO_FLUSHER (PF_MEMALLOC_NOIO | PF_LOCAL_THROTTLE)

/**
 * 克隆标志：
 */
enum {
	__CSIGNAL = 8,
	__CLONE_VM = 8,
	__CLONE_FS = 9,
	__CLONE_FILES = 10,
	__CLONE_SIGHAND = 11,
	__CLONE_PID = 12,
	__CLONE_PTRACE = 13,
	__CLONE_VFORK = 14,
	__CLONE_PARENT = 15,
	__CLONE_THREAD = 16,
	__CLONE_NEWNS = 17,
	__CLONE_SYSVSEM = 18,
	__CLONE_SETTLS = 19,
	__CLONE_PARENT_SETTID = 20,
	__CLONE_CHILD_CLEARTID = 21,
	__CLONE_DETACHED = 22,
	__CLONE_UNTRACED = 23,
	__CLONE_CHILD_SETTID = 24,
	__CLONE_NEWCGROUP = 25,
	__CLONE_NEWUTS = 26,
	__CLONE_NEWIPC = 27,
	__CLONE_NEWUSER = 28,
	__CLONE_NEWPID = 29,
	__CLONE_NEWNET = 30,
	__CLONE_IO = 31,
};

#define CSIGNAL			BIT_ALL(__CSIGNAL)		/* 退出时发送的信号掩码 */
#define CLONE_VM		BIT(__CLONE_VM)			/* 如果进程间共享虚拟内存空间，则设置 */
#define CLONE_FS		BIT(__CLONE_FS)			/* 如果进程间共享fs信息则设置 */
#define CLONE_FILES		BIT(__CLONE_FILES)		/* 如果进程间共享打开的文件则设置 */
#define CLONE_SIGHAND	BIT(__CLONE_SIGHAND)	/* 如果进程间共享信号处理函数和阻塞信号则设置 */
#define CLONE_PID		BIT(__CLONE_PID)		/* 如果进程间共享 pid 则设置 */
#define CLONE_PTRACE	BIT(__CLONE_PTRACE)		/* 如果我们也想让子进程继续被跟踪则设置 */
#define CLONE_VFORK		BIT(__CLONE_VFORK)		/* 如果父进程希望子进程在内存释放时唤醒它则设置 */
#define CLONE_PARENT	BIT(__CLONE_PARENT)		/* 如果我们想让父节点与克隆体的父节点相同则进行设置 */
#define CLONE_THREAD	BIT(__CLONE_THREAD)		/* 相同的线程组？*/
#define CLONE_NEWNS		BIT(__CLONE_NEWNS)		/* 新的挂载命名空间组 */
#define CLONE_SYSVSEM	BIT(__CLONE_SYSVSEM)	/* 共享system V SEM_UNDO */
#define CLONE_SETTLS	BIT(__CLONE_SETTLS)		/* 为子进程创建一个新的TLS */
#define CLONE_PARENT_SETTID	BIT(__CLONE_PARENT_SETTID)	/* 在父进程中设置TID */
#define CLONE_CHILD_CLEARTID	BIT(__CLONE_CHILD_CLEARTID)	/* 在子进程中清除TID */
#define CLONE_DETACHED	BIT(__CLONE_DETACHED)	/* 未使用，忽略之 */
#define CLONE_UNTRACED	BIT(__CLONE_UNTRACED)	/* 不在当前线程上进行追踪 */
#define CLONE_CHILD_SETTID	BIT(__CLONE_CHILD_SETTID)	/* 在子进程中设置TID */
#define CLONE_NEWCGROUP	BIT(__CLONE_NEWCGROUP)	/* 新的cgroup命名空间 */
#define CLONE_NEWUTS	BIT(__CLONE_NEWUTS)		/* 新的utsname命名空间 */
#define CLONE_NEWIPC	BIT(__CLONE_NEWIPC)		/* 新的ipc命名空间 */
#define CLONE_NEWUSER	BIT(__CLONE_NEWUSER)	/* 新的用户命名空间 */
#define CLONE_NEWPID	BIT(__CLONE_NEWPID)		/* 新的pid命名空间 */
#define CLONE_NEWNET	BIT(__CLONE_NEWNET)		/* 新的网络命名空间 */
#define CLONE_IO		BIT(__CLONE_IO)			/* 新的IO命名空间 */

#define CLONE_SIGNAL	(BIT(__CLONE_SIGHAND) | BIT(__CLONE_THREAD))

#define NEW_TO_OLD_UID(uid)	(uid)
#define NEW_TO_OLD_GID(gid)	(gid)

/*
 * 默认的RR调度时间,100ms
 */
#define RR_TIMESLICE		(100 * HZ / 1000)

#define INIT_TIMER_SLACK_NS 50000

/**
 * 任务初始化时的抢占计数为2
 */
#define INIT_TASK_PREEMPT_COUNT 2

/**
 * 任务描述符
 */
struct task_desc {
	/**
	 * 魔法值
	 */
	int 			magic;
	/**
	 * 保护任务结构字段的自旋锁
	 */
	struct smp_lock lock;
	/**
	 * 任务标志
	 */
	unsigned int 	flags;

	/**
	 * 原子标志位
	 */
	unsigned long atomic_flags;
	/**
	 * 任务当前状态，如TASK_INTERRUPTIBLE
	 */
	volatile long 	state;
	/**
	 * 任务堆栈，即process_desc描述符
	 */
	void			*stack;
	/**
	 * 任务调度优先级，当前按此优先级进行调度
	 * 可能比创建时的优先级有所提高或者降低
	 */
	int 			sched_prio;
	/**
	 * 任务优先级，创建时的优先级
	 */
	int			prio;
	/**
	 * 任务调度策略
	 */
	int 			sched_policy;
	/**
	 * 时间片运行时间
	 */
	unsigned int		ts_time;
	/**
	 * 是否在运行队列中
	 */
	bool			in_run_queue;
	/**
	 * 通过此字段将任务放进运行队列 
	 */
	struct double_list 		run_list;
	/**
	 * 通过此字段将任务放进全局链表
	 */	
	struct double_list 		all_list;
	/**
	 * 通过此字段将任务放进全局链表
	 */
	struct double_list		sched_all_list;
	struct double_list		global_all_list;
	/**
	 * 任务所属的用户id、组id
	 */
	uid_t uid;
	uid_t euid;
	uid_t suid;
	
	/**
	 * 组id
	 */
	gid_t gid;
	gid_t egid;
	gid_t sgid;
	/**
	 * 文件系统id
	 */
	uid_t fsuid;
	gid_t fsgid;
	gid_t pgrp;
	
	/**
	 * 任务、任务组ID
	 */
	pid_t pid, gpid;
	/**
	 * 任务组领头进程
	 */
	struct task_desc* gleader;
	/**
	 * 任务的引用计数
	 */
	struct ref_count	ref;
	
	/**
	 * 用户态寄存器现场
	 * 目前未用
	 */
	struct exception_spot *user_regs;
	/**
	 * 是否处于系统调用中
	 * 为了在内核态支持系统调用
	 */
	int		in_syscall;
	/**
	 * 临时变量，有点奇怪
	 * 用于释放描述符，以后会废弃
	 */
	struct task_desc 		*prev_sched;
	/**
	 * 线程主函数
	 */
	void	*task_main;

	/**
	 * 传给线程主函数的参数
	 */
	void		*main_data;

	/**
	 * 任务退出代码
	 */
	int			exit_code;
	/**
	 * 任务退出时向父进程发出的信号
	 */
	int 		exit_signal;
	/**
	 * 应用模式
	 */
	int create_mode;
	/**
	 * 指向线程私有的内存区域
	 */ 
	unsigned long tp_value;

	int __user			*set_child_tid;
	int __user			*clear_child_tid;
	/**
	 * 用于模拟旧版本内核的ABI行为。
	 */
	unsigned int			personality;

	/**
	 * 与当前任务相关的文件句柄结构
	 * 目前使用全局数组。
	 */
	struct task_file_handles	*files;
	/**
	 * 与文件系统相关的信息。如当前目录。
	 */
	struct task_fs_context *fs_context;
	/**
	 * 文件系统在查找路径时使用
	 * 避免符号链接查找深度过深，导致死循环。
	 */
	struct {
		/**
		 * 递归链接查找的层次。
		 * link_count调用链接查找的总次数。
		 */
		int nested_count;
		/**
		 * 调用链接查找的总次数。
		 */
		int link_count;
	} fs_search;
	/**
	 * 任务当前使用的tty
	 */
	struct tty_struct *tty;
	/**
	 * 当前活动日志操作处理的地址。
	 * 正在使用的原子操作对象。
	 */
	void *journal_info;
	/**
	 * 在系统调用wait4中睡眠的进程的等待队列。
	 */
	struct wait_queue		wait_child_exit;

	/**
	 * 用户态程序执行相关信息
	 * 包含命令行和环境变量等信息
	 */
	struct exec_info*  user_exec_info;
	/**
	 * 任务调度\恢复的寄存器现场
	 */
	struct task_spot		task_spot;
	struct fp_context* fp_regs;	
	unsigned long parent_exec_id;
   	unsigned long self_exec_id;
	//进程绑定的timer(由sys_setitimer使用)
	struct timer real_timer;
	unsigned long it_real_value;
	unsigned long it_real_incr;
	/**
	 * 时间松弛值；
	 * 它们用于poll()和select()等超时值进行四舍五入
	 * 它们的单位是纳秒。
	 */
	unsigned long timer_slack_ns;
	unsigned long default_timer_slack_ns;
	/**
	 * 线程地址限制
	 */
	unsigned long addr_limit;
		/**
	 * 目前没有使用这些字段，且默认值为0
	 */
	unsigned long min_flt;
	unsigned long maj_flt;
	unsigned long nswap;
	unsigned long cmin_flt;
	unsigned long cmaj_flt;
	unsigned long cnswap;
	char 		name[TASK_NAME_LEN];
	/**
	 * 用户态进程 : 二进制文件路径
	 */
	char		bin_path[BIN_PATH_MAX];
};

#define __sched		__attribute__((__section__(".sched.text")))

/**
 * 全局静态的任务堆栈，用于boot cpu的idle进程
 * 避免在系统启动阶段分配内存
 */
extern union process_union master_idle_stack;

extern struct task_desc *idle_task_desc[];
static inline struct task_desc *idle_task(int cpu)
{
	return idle_task_desc[cpu];
}

static inline void
__set_task_state(struct task_desc *tsk, unsigned long state)
{
	tsk->state = state;
}

/**
 * 设置进程状态。同时会加上内存屏障。
 */
static inline void
set_task_state(struct task_desc *tsk, unsigned long state)
{
	tsk->state = state;
	smp_mb();
}

/**
 * 设置当前进程状态。无内存屏障。
 */
static inline void
__set_current_state(unsigned long state)
{
	current->state = state;
}

/**
 * 设置当前进程状态。同时会加上内存屏障。
 */
static inline void
set_current_state(unsigned long state)
{
	set_task_state(current, state);
}

#define task_process_info(task)	((struct process_desc *)(task)->stack)
#define task_stack_bottom(task)	((task)->stack)

static inline int test_task_proc_flag(struct task_desc *tsk, int flag)
{
	return __test_process_flag(task_process_info(tsk), flag);
}

static inline void set_task_proc_flag(struct task_desc *tsk, int flag)
{
	__set_process_flag(task_process_info(tsk), flag);
}

static inline void set_task_need_resched(struct task_desc *tsk)
{
	set_task_proc_flag(tsk, PROCFLAG_NEED_RESCHED);
}

static inline void clear_task_need_resched(struct task_desc *tsk)
{
	__clear_process_flag(task_process_info(tsk), PROCFLAG_NEED_RESCHED);
}

static inline int need_resched(void)
{
	return unlikely(test_process_flag(PROCFLAG_NEED_RESCHED));
}

static inline void set_need_resched(void)
{
	set_process_flag(PROCFLAG_NEED_RESCHED);
}

static inline void clear_need_resched(void)
{
	clear_process_flag(PROCFLAG_NEED_RESCHED);
}

static inline int signal_pending(struct task_desc *p)
{
	return unlikely(test_task_proc_flag(p, PROCFLAG_SIGPENDING));
}

static inline void task_lock(struct task_desc *tsk)
{
	smp_lock(&tsk->lock);
}

static inline void task_unlock(struct task_desc *tsk)
{
	smp_unlock(&tsk->lock);
}

/**
 * 全局任务链表
 */

/**
 * 任务描述符引用计数
 */
#define hold_task_desc(tsk)	ref_count_hold(&(tsk)->ref)
extern void __release_task_desc(struct ref_count *ref);
#define loosen_task_desc(tsk)	ref_count_loosen(&(tsk)->ref, __release_task_desc)

/**
 * 全局任务链表
 */
extern struct double_list sched_all_task_list;
static inline struct task_desc *next_task(struct task_desc *p)
{
	struct task_desc *next;

	if (p->all_list.next == &sched_all_task_list)
		return NULL;

	next = list_container(p->all_list.next, struct task_desc, all_list);
	return next;
}

static inline struct task_desc *first_task(void)
{
	if (list_is_empty(&sched_all_task_list))
		return NULL;
	else	
		return list_container(sched_all_task_list.next, struct task_desc, all_list);
}

/**
 * 遍历所有任务
 */
#define for_each_task(p) \
	list_for_each_entry(p, &(sched_all_task_list), all_list)

#define rt_task(p) 1

#define MAX_SCHEDULE_TIMEOUT ((unsigned long)(~0UL>>1))
signed long schedule_timeout(signed long timeout);

extern long io_schedule_timeout(long timeout);
static inline void io_schedule(void)
{
	io_schedule_timeout(MAX_SCHEDULE_TIMEOUT);
}


#define rq_lock_irqsave(flags)
// smp_lock_irqsave(&current_runqueue->lock, flags)
#define rq_unlock(void)
// smp_unlock(&current_runqueue->lock)
#define rq_unlock_irq(void) 
// smp_unlock_irq(&current_runqueue->lock)
#define rq_unlock_irqrestore(flags)
// smp_unlock_irqrestore(&current_runqueue->lock, flags)


void free_proc_stack(void *addr);
void free_task_desc(struct task_desc* t);
pid_t get_new_pid(void);
int init_task_sched(struct task_desc * tsk, int sched_policy);

extern int capable(int cap);
extern int in_group_p(gid_t grp);
int is_orphaned_pg(int pgrp);
int init_task_fs(struct task_desc *parent, struct task_desc *new);
void loosen_fs_context(struct task_fs_context *fs);
void loosen_file_handles(struct task_file_handles *files);
int exit_task_fs(struct task_desc *tsk);

extern asmlinkage void schedule(void);
extern asmlinkage void preempt_in_irq(void);
void sched_update_timeslice(struct task_desc * p);
int wake_up_process_special(struct task_desc *tsk,
	unsigned int state, int sync);
int wake_up_process(struct task_desc *tsk);
extern struct task_desc * __switch_cpu_context(struct task_desc *prev,
	struct task_desc *next);

extern int process_signal(struct exception_spot *regs);
extern int post_signal(unsigned long sig,struct task_desc * p,int priv);
extern int post_signal_to_proc(int pid, int sig, int priv);
extern int post_signal_to_procgroup(int pgrp, int sig, int priv);
extern void task_entry(void);
static inline int kthread_stop(struct task_desc *k)
{
	/* TO-DO */
	return 0;
}

static inline int kthread_should_stop(void)
{
	/* TO-DO */
	return 0;
}

static inline void kthread_bind(struct task_desc *k, unsigned int cpu)
{
	/* TO-DO */
}

static inline int is_rt_prio(int prio)
{
	if (unlikely(prio < MAX_RT_PRIO))
		return 1;
	return 0;
}

static inline int is_rt_task(struct task_desc *t)
{
	return is_rt_prio(t->prio);
}

static inline struct process_desc* task_on_process(const struct task_desc *t)
{
	return (struct process_desc*)(t->stack);
}

static inline struct mem_desc* task_on_mem(const struct task_desc *t)
{
	return task_on_process(t)->mem;
}

struct task_desc *kthread_create(int (*threadfn)(void *data),
			void *data, int prio, const char namefmt[], ...);
void init_idle_process(union process_union *stack,
		struct task_desc *proc, int cpu);
/**
 * 模块初始化函数
 *	init_sched_early:早期初始化，只能使用bootmem分配
 *	init_sched:初始化
 */
extern void init_sched_early(void);
extern void init_sched(void);

#endif /* __KERNEL__ */

#endif /* __DIM_SUM_SCHED_H */
